<html>
  <head>
    <title>Local Storage Session Pref Override</title>
    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    <script>
      const ACCEPT_SESSION = 2;

      add_task(function*() {
        yield new Promise((resolve, reject) => {
          SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy",
                                              ACCEPT_SESSION]]},
                                    resolve);
        });

        // Before setting permission
        yield new Promise((resolve) => {
          var frame = document.createElement('iframe');
          frame.src = "frameLocalStorageSessionOnly.html";

          var listener = (e) => {
            is(e.data, true, "Before adding permission should be session only");
            window.removeEventListener('message', listener);
            resolve();
          };
          window.addEventListener('message', listener);
          document.body.appendChild(frame);
        });

        // After setting permission
        yield new Promise((resolve) => {
          SpecialPowers.pushPermissions([{"type": "cookie", "allow": 1, "context": document}],
                                        resolve);
        });

        yield new Promise((resolve) => {
          var frame = document.createElement('iframe');
          frame.src = "frameLocalStorageSessionOnly.html";

          var listener = (e) => {
            is(e.data, false, "After adding permission should not be session only");
            window.removeEventListener('message', listener);
            resolve();
          };
          window.addEventListener('message', listener);
          document.body.appendChild(frame);
        });
      });
    </script>
  </head>
  <body>
  </body>
</html>
